package com.zebone.mongodb;

import java.util.ArrayList;
import java.util.List;

import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;

import com.mongodb.MongoClient;
import com.zebone.morphia.entity.UhDcPi2Ref;
import com.zebone.morphia.entity.UhDcPiAllergy;
import com.zebone.morphia.entity.UhDcPiCard;
import com.zebone.morphia.entity.UhDcPiDisease;
import com.zebone.morphia.entity.UhDcPiExp;
import com.zebone.morphia.entity.UhDcPiFamily;

public class TestEmpiInfoInsert2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Morphia morphia = new Morphia();

		// tell Morphia where to find your classes
		// can be called multiple times with different packages or classes
		morphia.mapPackage("com.zebone.morphia.entity");

		// create the Datastore connecting to the default port on the local host
		Datastore datastore = morphia.createDatastore(new MongoClient("192.168.90.229",3333), "test");
		datastore.ensureIndexes();
		
		for(int i=0;i<1;i++){
			UhDcPi2Ref uhDcPi = new UhDcPi2Ref();
			uhDcPi.setPk_pati(String.valueOf(i));
			uhDcPi.setCode_group("group_zebone"+i);
			uhDcPi.setCode_org("org_zebone"+i);
			uhDcPi.setPati_code("pati"+i);
			uhDcPi.setEmpi(String.valueOf(i));
			uhDcPi.setPati_name("振绑"+i);
			uhDcPi.setId_no("zeboneidno"+i);
			uhDcPi.setAss_no("yibaoka"+i);
		    uhDcPi.setDate_birth("20121220090812");
		    
		    List<UhDcPiCard> udpcList = new ArrayList<>();
		    
		    List<UhDcPiAllergy> udpaList = new ArrayList<>();
		    
		    List<UhDcPiDisease> uhDcPiDiseaseList = new ArrayList<>();
		    
		    List<UhDcPiExp> uhDcPiExpList = new ArrayList<>();
		    
		    List<UhDcPiFamily> uhDcPiFamilyList = new ArrayList<>();
		    
		    for(int j=0;j<=10000;j++){
		    	UhDcPiCard card = new UhDcPiCard();
		    	card.setCode_card_type(String.valueOf(j));
		    	card.setName_card_type("卡"+String.valueOf(j));
		    	card.setCard_no(String.valueOf(j));
		    	udpcList.add(card);
		    	
		    	UhDcPiAllergy allergy = new UhDcPiAllergy();
		    	allergy.setCode_allergy_source("allergy"+j);
		    	allergy.setName_allergy_source("过敏源"+j);
		    	udpaList.add(allergy);		    	
		    
		    	UhDcPiDisease udpd = new UhDcPiDisease();
		    	udpd.setCode_disease("disease"+j);
		    	udpd.setName_disease("疾病"+j);
		    	uhDcPiDiseaseList.add(udpd);
		    	
		        UhDcPiExp udpe = new UhDcPiExp();
		        udpe.setCode_exp_type("exp"+j);
		        udpe.setName_exp_type("暴露"+j);
		        uhDcPiExpList.add(udpe);
		        
		        UhDcPiFamily udpf = new UhDcPiFamily();
		        udpf.setCode_dise("dise"+j);
		        udpf.setName_dise("家庭史"+j);
		        uhDcPiFamilyList.add(udpf);
		    }
		    datastore.save(udpcList);
		    datastore.save(udpaList);
		    datastore.save(uhDcPiDiseaseList);
		    datastore.save(uhDcPiExpList);
		    datastore.save(uhDcPiFamilyList);
		    
		    uhDcPi.setUhDcPiCardList(udpcList);
		    uhDcPi.setUhDcPiAllergyList(udpaList);
		    uhDcPi.setUhDcPiExpList(uhDcPiExpList);
		    uhDcPi.setUhDcPiFamilyList(uhDcPiFamilyList);
			datastore.save(uhDcPi);   
		}
		
	}

}
